<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Freelancer\AuthController;
use App\Http\Controllers\Freelancer\TaskController;
use App\Http\Controllers\Freelancer\ContractController;
use App\Http\Controllers\Freelancer\ProfileController;
use App\Http\Controllers\Freelancer\SettlementController;
use App\Http\Controllers\Freelancer\ContractSignController;

/*
|--------------------------------------------------------------------------
| Freelancer API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for freelancer application.
|
*/

Route::prefix('api/freelancer')->group(function () {
    // 公共路由（无需认证）
    Route::post('send-sms-code', [AuthController::class, 'sendSmsCode']);
    Route::post('login', [AuthController::class, 'login']);
    Route::post('login_by_weixin', [AuthController::class, 'loginByWeixin']);
    Route::any('wechat/verify-token', [AuthController::class, 'verifyToken']);
    // Route::post('register', [AuthController::class, 'register']);

    // 任务相关公共接口
    Route::get('tasks/{id}', [TaskController::class, 'show']);

    // 需要认证的路由
    Route::middleware(['auth:freelancer'])->group(function () {
        // 认证相关
        Route::get('me', [AuthController::class, 'me']);
        Route::post('logout', [AuthController::class, 'logout']);
        Route::post('delete-account', [AuthController::class, 'deleteAccount']);

        // 任务相关
        Route::get('tasks/{task}/latest-application', [TaskController::class, 'latestApplication']);
        Route::post('apply-task', [TaskController::class, 'applyTask']);

        // 合同记录
        Route::get('contracts', [ContractController::class, 'index']);
        Route::get('contracts/{id}', [ContractController::class, 'show']);
        Route::get('contracts/{id}/download', [ContractController::class, 'download']);
        Route::post('sign-contract', [ContractSignController::class, 'sign']);

        // 个人资料
        Route::get('profile', [ProfileController::class, 'show']);
        Route::put('profile', [ProfileController::class, 'update']);
        Route::post('profile/real-name-verify', [ProfileController::class, 'realNameVerify']);
        Route::post('profile/id-card-ocr', [ProfileController::class, 'idCardOcr']);
        Route::post('profile/face-recognition', [ProfileController::class, 'faceRecognition']);

        // 结算记录
        Route::get('settlements', [SettlementController::class, 'index']);
        Route::get('settlements/{id}', [SettlementController::class, 'show']);
        Route::get('settlements-statistics', [SettlementController::class, 'statistics']);
        Route::get('settlement-status-options', [SettlementController::class, 'statusOptions']);
    });
});
